home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / util / misc / lha2lzx.lha / lha2lzx next >
Text File  |  1995-08-04  |  3KB  |  152 lines

  1. /* Script to Convert lha archives to lzx archives  */
  2. /* C J Hewitt 4/8/95  lha2lzx Version 1.00         */
  3.  
  4. Parse Arg Archive Options
  5.  
  6. TempDir = '' /* Temp Directory */
  7. Nil = ''  /* For Quiet option  */
  8.  
  9. /* Set error handling code */
  10. Signal On Error
  11. Signal On Break_C
  12.  
  13. if Archive = '?' then
  14. do
  15.     say 'Valid Options: [rx] lha2lzx <Archive> [Temp <TempDir>] [Delete] [Quiet]'
  16.     exit
  17. end
  18.  
  19. if Archive = '' then
  20. do
  21.     say "lha2lzx: You must enter an archive"
  22.     exit
  23. end
  24.  
  25. if ~exists(Archive) then
  26. do
  27.     say "lha2lzx: Cannot open "Archive". Object not found"
  28.     exit
  29. end
  30.  
  31. /* Separate filename from path */
  32.  
  33. Dev = ''
  34. Parse Var Archive Dev ':' Rest
  35.  
  36. if Rest = '' & Dev ~= '' then
  37. do
  38.     Rest = Dev
  39.     Dev = ''
  40. end
  41.  
  42. Path = ''
  43. PPath = ''
  44. do while (Rest ~= "")
  45.     Parse Var Rest PPath '/' Rest
  46.     if Rest ~= "" then
  47.     do
  48.         if Path = "" then
  49.             Path = PPath
  50.         else
  51.             Path = Path || '/' || PPath
  52.     end
  53. end
  54.  
  55. if Dev = '' then
  56.     FullPath = Path
  57. else
  58.     FullPath = Dev || ':' || Path
  59.  
  60. if Path ~= '' then
  61.     FullPath = FullPath || '/'
  62.  
  63. FileName = PPath
  64.  
  65. /* Determine if valid filename (ie does it end in .lha */
  66.  
  67. if Upper(Right(FileName,3)) ~= 'LHA' then
  68. do
  69.     say "Not a valid lha archive name"
  70.     exit
  71. end
  72.  
  73. Delete = FALSE
  74. Temp = ""
  75. do while (Options ~= "")
  76.     Parse Upper value Options with Opt Options
  77.     if Opt = "TEMP" then
  78.         parse value Options with Temp Options
  79.  
  80.     if Opt = "DELETE" then
  81.         Delete = TRUE
  82.  
  83.     if Opt = "QUIET" then
  84.         Nil = '> Nil:'
  85. end
  86.  
  87. if Temp = "" then
  88.     Temp = "T:"
  89.  
  90. if Right(Temp, 1) = ":" | Right(Temp, 1) = "/"
  91. then
  92.     Slash = ""
  93. else
  94.     Slash = "/"
  95.  
  96. Temp = Temp || Slash
  97.  
  98. /* get basename of Archive */
  99.  
  100. Basename = Left(Filename,Length(FileName)-4)
  101.  
  102. TempDir = Temp"lha"Random(,,time(s))"/"
  103.  
  104. dummy=PRAGMA('D',FullPath)
  105.  
  106. FullPath = PRAGMA('D')  /* Get actual path in case relative paths have been used */
  107. if Right(FullPath,1) ~= ":" then
  108.     FullPath = FullPath'/'
  109.  
  110. address command
  111.  
  112. say "Unarchiving" Archive "To Temp Directory......"
  113.  
  114. 'lha x' FileName TempDir Nil
  115.  
  116. say "Creating lzx Archive......."
  117.  
  118. dummy=PRAGMA('D',TempDir) /* Change to Temp Directory */
  119.  
  120. 'lzx a -r 'FullPath || BaseName || '.lzx' '#?' Nil
  121.  
  122. address rexx  /* Gets confused with next line if using Ram Disk: as temp dir if we don't do this */
  123.  
  124. dummy=PRAGMA('D',FullPath) /* Change to start dir so we can delete temp directory & delete orignal archive if required */
  125.  
  126. address command  /* Now we can switch back to AmigaDOS */
  127.  
  128. 'delete' TempDir 'all quiet'
  129.  
  130. /* If Delete has been specified on command line then delete original file  */
  131. if Delete = TRUE then
  132.     'delete' FileName
  133.  
  134. exit
  135.  
  136. /* Error Handling Code */
  137.  
  138. Break_C:
  139. Error:
  140.     ErrStr = "lha2lzx: Conversion Failed."
  141.     if Delete = TRUE then
  142.         ErrStr = ErrStr "Original Archive Not Deleted."
  143.  
  144.     Say ErrStr
  145.     dummy = PRAGMA('D','SYS:')      /* Change to 'safe' directory */
  146.     if TempDir ~= '' & Exists(TempDir) then
  147.     do
  148.         address command
  149.         'delete' Temp 'all quiet'
  150.     end
  151.     exit(30)
  152.